package com.zhkjnet.zhyy.service;

import com.zhkjnet.zhyy.dao.OilCardDao;
import com.zhkjnet.zhyy.entity.OilCard;
import com.zhkjnet.zhyy.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class OilCardService {

    @Autowired
    private OilCardDao oilCardDao;

    @Transactional
    public void save(OilCard oilCard, User user) {
        oilCard.setUser(user);
        oilCard.setDeleted(false);
        oilCard.setCreateTime(new Date());
        oilCard.setDayTimes(0);
        oilCardDao.save(oilCard);
    }

    @Transactional
    public void deleteById(Long id) {
        OilCard oilCard = new OilCard();
        oilCard.setId(id);
        oilCard.setDeleted(true);
        oilCardDao.update(oilCard);
    }

    public List<OilCard> findAllByUserId(Long userId) {
        return oilCardDao.findAllByUserId(userId);
    }

    public OilCard findById(Long id) {
        return oilCardDao.findById(id);
    }

    @Transactional
    public void setZero() {
        oilCardDao.setZero();
    }
}
